
var TableController = function($scope, $http, ngTableParams){
	
	$http.defaults.headers.post["Content-Type"] = "application/json";
	var urlBase="http://localhost:8080/angularjs";
	
	var data = [];
	
	$scope.getAllTodo = function(){
		$http.get(urlBase + '/todo/all.json').success(function(respone){
			data = respone;
			console.log(data.length);
			// importance: because scope of data outsite this function reset. when this function
			// data.length = 12. outsite: data.length = 0
			$scope.dynamicTable(data);
		}).error(function(){
		});
	}
	
	$scope.getAllTodo();
	
	$scope.dynamicTable = function(data){
	    $scope.tableParams = new ngTableParams({
	        page: 1,            // show first page
	        count: 10           // count per page
	    }, {
	        total: data.length, // length of data
	        getData: function($defer, params) {
	            $defer.resolve(data.slice((params.page() - 1) * params.count(), params.page() * params.count()));
	        }
	    });
	}
}